package com.ushine.web.template.authority.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ushine.web.base.model.system.UserDO;
import com.ushine.web.component.authority.annotation.DataPermissionFilter;
import com.ushine.web.component.exception.ServiceException;
import com.ushine.web.template.authority.mapper.StaffMapper;
import com.ushine.web.template.authority.model.StaffDO;
import com.ushine.web.template.authority.service.IStaffService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: yls
 * @Date 2022/2/9 16:02
 * @Description: 数据隔离测试实现层
 * @Version 1.0
 **/
@Service
public class StaffServiceImpl extends ServiceImpl<StaffMapper, StaffDO> implements IStaffService {

    @Override
    @Transactional(readOnly = true)
    public List<StaffDO> listStaffsByThread() {
        return list();
    }

    @Override
    @Transactional(readOnly = true)
    @DataPermissionFilter(function = "staff:select:listAll")
    public List<StaffDO> listStaffs() {
        return list();
    }

    @Override
    @Transactional(readOnly = true)
    @DataPermissionFilter(function = "staff:select:listAll")
    public List<StaffDO> listStaffsByThread(UserDO user) {
        return list();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean insertStaff(StaffDO staff) {
        return save(staff);
    }

    @Override
    public Boolean updateStaff(StaffDO staff) {
        LambdaUpdateWrapper<StaffDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(StaffDO::getId, staff.getId());
        lambdaUpdateWrapper.set(StaffDO::getCity, staff.getCity());
        return update(lambdaUpdateWrapper);
    }

    @Override
    public Boolean updateStaffByWrapper(Wrapper<StaffDO> updateWrapper) throws ServiceException {
        return update(updateWrapper);
    }

    @Override
    public Boolean deleteAllStaff() {
        LambdaQueryWrapper<StaffDO> queryWrapper = new LambdaQueryWrapper<>();
        return remove(queryWrapper);
    }


}
